package engine.render;

import static org.lwjgl.opengl.GL11.*;

public class GLEngine
{
    
    public GLEngine()
    {
    }
    
    public void setGLStates()
    {
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_CULL_FACE);
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
        
        glDepthFunc(GL_LEQUAL);
        glFrontFace(GL_CCW);
        this.setCullingFace(GL_BACK);
        glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
        glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    }
    
    public void clearBuffers()
    {
        glClear(
            GL_COLOR_BUFFER_BIT | 
            GL_DEPTH_BUFFER_BIT | 
            GL_STENCIL_BUFFER_BIT
        );
    }
    
    public void setViewportSize(int width, int height)
    {
        glViewport(0, 0, width, height);
    }
    
    public void setCullingFace(final int enumVal)
    {
        glCullFace(enumVal);
    }
    
    public void setColorWrite(boolean enabled)
    {
        glColorMask(enabled, enabled, enabled, enabled);
    }
    
    public void setDepthWrite(boolean enabled)
    {
        glDepthMask(enabled);
    }
    
    public void destroy()
    {
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_CULL_FACE);
        glDisable(GL_BLEND);
        glDisable(GL_TEXTURE_2D);
    }
    
}
